package singleton;

/**
 * 饿汉式
 */
public class HungerySingletonTest {
    public static void main(String[] args) {
        for (int i = 0; i < 10; i++) {
            new Thread(()->{
                System.out.println(HungerySingleton.getInstance());
            },"i="+i).start();
        }
    }
}
class HungerySingleton{
    private static HungerySingleton instance = new HungerySingleton();

    // 构造私有
    private HungerySingleton(){}

    // 提供对外获取方式
    public static HungerySingleton getInstance() {
        return instance;
    }
}
